package com.lagou.controller;

import com.lagou.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/email")
@Slf4j
public class EmailController {

    @Autowired
    private MailService mailService;

    @RequestMapping("/{email}/{code}")
    public String sendEmail(@PathVariable("email")String email,@PathVariable("code") String code){
        // 发送验证码到邮箱，true成功，false失败
        log.info("begin send email");
        try {
            mailService.sendSimpleTextMailActual(email+" 注册", "注册网站code:"+code, new String[]{email}, null, null, null);

            return "true";
        }catch (Exception e){

            return "false";
        }
    }

    @RequestMapping(value = "/send")
    public String send(){
        mailService.sendSimpleTextMailActual("发送主题","发送内容",new String[]{"397322243@qq.com","1073913580@qq.com"},null,null,null);
        return "1";
    }

}
